﻿#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

FROM node20-dotnet8:1.0.0-alpha.2 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["nuget.config", "./"]
COPY ["quick-bootstrap/quick-bootstrap.esproj", "quick-bootstrap/"]
COPY ["quick-bootstrap/package.json", "quick-bootstrap/"]
COPY ["quick-bootstrap/pnpm-lock.yaml", "quick-bootstrap/"]
COPY ["Quickly.Identity.EntityFrameworkCore/Quickly.Identity.EntityFrameworkCore.csproj", "Quickly.Identity.EntityFrameworkCore/"]
COPY ["Quickly.Identity/Quickly.Identity.csproj", "Quickly.Identity/"]
COPY ["Quickly.Identity.Portal/Quickly.Identity.Portal.csproj", "Quickly.Identity.Portal/"]
RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages dotnet restore "./Quickly.Identity.Portal/Quickly.Identity.Portal.csproj" 

WORKDIR "/src/quick-bootstrap"
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install

WORKDIR "/src"
COPY . .
RUN dotnet build "./Quickly.Identity.Portal/Quickly.Identity.Portal.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Quickly.Identity.Portal/Quickly.Identity.Portal.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Quickly.Identity.Portal.dll"]